//package com.gxgeek.springboothbase;
//
//import org.apache.hadoop.conf.Configuration;
//import org.apache.hadoop.hbase.*;
//import org.apache.hadoop.hbase.client.*;
//
//import java.io.IOException;
//
///**
// * @author gaoxing
// * @create 2018-08-02 下午2:34
// */
//public class HBaseConnection {
//    private String rootDir;
//    private String zkServer;
//    private String port;
//    private Configuration conf;
//    private HConnection hConn = null;
//
//    private HBaseConnection(String rootDir,String zkServer,String port) throws IOException {
//        this.rootDir = rootDir;
//        this.zkServer = zkServer;
//        this.port = port;
//
//        conf = HBaseConfiguration.create();
//        conf.set("hbase.rootdir", rootDir);
//        conf.set("hbase.zookeeper.quorum", zkServer);
//        conf.set("hbase.zookeeper.property.clientPort", port);
//
//        hConn = HConnectionManager.createConnection(conf);
//    }
//
//    public static void main(String[] args) {
//        Configuration config = HBaseConfiguration.create();
//        String zkAddress = "hb-bp1f5xxxx48a0r17i-001.hbase.rds.aliyuncs.com:2181,hb-bp1f5xxxx48a0r17i-002.hbase.rds.aliyuncs.com:2181,hb-bp1f5xxxx48a0r17i-003.hbase.rds.aliyuncs.com:2181";
//        config.set(HConstants.ZOOKEEPER_QUORUM, zkAddress);
//        Connection connection = null;
//        try {
//            connection = ConnectionFactory.createConnection(config);
//            HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(TABLE_NAME));
//            tableDescriptor.addFamily(new HColumnDescriptor(CF_DEFAULT));
//            System.out.print("Creating table. ");
//            Admin admin = connection.getAdmin();
//            admin.createTable(tableDescriptor);
//            System.out.println(" Done.");
//            Table table = connection.getTable(TableName.valueOf(TABLE_NAME));
//            try {
//                Put put = new Put(ROWKEY);
//                put.addColumn(CF_DEFAULT.getBytes(), QUALIFIER, "this is value".getBytes());
//                table.put(put);
//                Get get = new Get(ROWKEY);
//                Result r = table.get(get);
//                byte[] b = r.getValue(CF_DEFAULT.getBytes(), QUALIFIER);  // returns current version of value
//                System.out.println(new String(b));
//            } finally {
//                if (table != null) table.close();
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        } finally {
//            if (connection != null) {
//                try {
//                    connection.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    }
//
//
//
//}
